home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / xcmd / sprtxtrn.sea / Support Tools eXternals 1.2.5 / card_40555.txt < prev    next >
Text File  |  1990-11-13  |  12KB  |  323 lines

  1. -- card: 40555 from stack: in.5
  2. -- bmap block id: 45194
  3. -- flags: 0000
  4. -- background id: 3858
  5. -- name: SCSINameToID
  6. ----- HyperTalk script -----
  7. on CloseCard
  8.   put empty into cd fld "id"
  9.   put empty into cd fld "volume"
  10.   pass CloseCard
  11. end CloseCard
  12.  
  13. on HideObjects
  14.   hide cd fld "label"
  15.   hide cd fld "volume"
  16.   hide cd fld "id"
  17.   hide cd btn "try it!"
  18. end HideObjects
  19.  
  20. on ShowObjects
  21.   show cd fld "label"
  22.   show cd fld "volume"
  23.   show cd fld "id"
  24.   show cd btn "try it!"
  25. end ShowObjects
  26.  
  27.  
  28. -- part 1 (field)
  29. -- low flags: 01
  30. -- high flags: 0002
  31. -- rect: left=83 top=192 right=212 bottom=237
  32. -- title width / last selected line: 0
  33. -- icon id / first selected line: 0 / 0
  34. -- text alignment: 0
  35. -- font id: 3
  36. -- text size: 12
  37. -- style flags: 0
  38. -- line height: 16
  39. -- part name: volume
  40.  
  41.  
  42. -- part 3 (button)
  43. -- low flags: 00
  44. -- high flags: A002
  45. -- rect: left=69 top=248 right=282 bottom=162
  46. -- title width / last selected line: 0
  47. -- icon id / first selected line: 0 / 0
  48. -- text alignment: 1
  49. -- font id: 0
  50. -- text size: 12
  51. -- style flags: 8192
  52. -- line height: 16
  53. -- part name: Try it!
  54. ----- HyperTalk script -----
  55. on mouseUp
  56.   global errGlobal
  57.   put VolumePath() into driveName
  58.   if driveName = empty then exit mouseUp
  59.   put SCSINameToID(driveName, "noDialog:errGlobal") into driveID
  60.   if errGlobal Γëá empty then
  61.     answer "Error:" && errGlobal
  62.     put empty into errGlobal
  63.     put empty into cd fld "id"
  64.     put empty into cd fld "volume"
  65.   else
  66.     put driveID into cd fld "id"
  67.     put driveName into cd fld "volume"
  68.   end if
  69. end mouseUp
  70.  
  71.  
  72.  
  73. -- part 4 (field)
  74. -- low flags: 01
  75. -- high flags: 0000
  76. -- rect: left=22 top=170 right=186 bottom=258
  77. -- title width / last selected line: 0
  78. -- icon id / first selected line: 0 / 0
  79. -- text alignment: 0
  80. -- font id: 3
  81. -- text size: 10
  82. -- style flags: 256
  83. -- line height: 13
  84. -- part name: label
  85.  
  86.  
  87. -- part 6 (field)
  88. -- low flags: 01
  89. -- high flags: 0002
  90. -- rect: left=21 top=192 right=212 bottom=82
  91. -- title width / last selected line: 0
  92. -- icon id / first selected line: 0 / 0
  93. -- text alignment: 1
  94. -- font id: 3
  95. -- text size: 12
  96. -- style flags: 256
  97. -- line height: 16
  98. -- part name: id
  99.  
  100.  
  101. -- part contents for background part 38
  102. ----- text -----
  103. 41/50
  104.  
  105. -- part contents for card part 4
  106. ----- text -----
  107. SCSI ID    SCSI Drive Name
  108.  
  109. -- part contents for background part 20
  110. ----- text -----
  111.      An XFCN which returns the SCSI ID of a SCSI drive with the specified name.
  112.  
  113.      Calling syntax : SCSINameToID(diskName,<ΓÇ£noDialogΓÇ¥:errorGlobal>)
  114.   DRIVENAME: the name of the SCSI drive to check.  
  115.  
  116.  
  117.  
  118. -- part contents for background part 42
  119. ----- text -----
  120. { SCSINameToID(diskName,ΓÇ£noDialog:ΓÇ¥errGlobal)                  }
  121. {}
  122. { XFCN returns the ID of a SCSI disk with a given             }
  123. {  name.                                                       }
  124. {}
  125. {   brought to you by:      Anup Murarka             Eric Carlson         }
  126. {                       ALINK:  SKEPTIC           ALINK:  cyNic   }
  127. {                                   CIS:  76004,3356         }
  128. {}
  129. {               We are part of the Support Tools Development Group,     }
  130. {               Apple Computer, Inc.      }
  131. {}
  132. {               please DO NOT contack Mac DTS for support of this code!    }
  133. {}
  134. {               please DO contact the authors for support of this code!     }
  135. {}
  136. {               Send comments, bug reports, requests to any of the above   }
  137. {               E-mail addresses or to:}
  138. {}
  139. {                           (one of us)                  }
  140. {                           Apple Computer, Inc.          }
  141. {                           900 E. Hamilton, Ave.          }
  142. {                           Campbell, CA   95008      }
  143. {                           M/S 72-L                     }
  144. {}
  145. {   Copyright:   ┬⌐ 1989, 1990 by Apple Computer, Inc., all rights reserved.     }
  146. {}
  147. { written by Eric Carlson                                        }
  148. { AppleLink:  cyNic                                              }
  149. { modification history                                                                                        }
  150. {          Date                  Initials                                    Comments                                   }
  151. {          ----              ------          ---------------------------------------------------- }
  152. {       1/5/90             ec            first written                                                                   }
  153. {       2/26/90           ec            added new "askedForHelp"                                                }
  154. {       4/25/90           ec            fixed bug when passed name of a non SCSI disk                      }
  155. {       5/25/90           ec            modified for A/UX compatibility.  changed name from        }
  156. {                                               ΓÇ£SCSINumberΓÇ¥ to ΓÇ£SCSINameToIDΓÇ¥.  changed version to  }
  157. {                                                1.1}
  158. {}
  159.  
  160. unit SCSINum;
  161.  
  162. interface
  163.     uses
  164.         HyperXCMD;
  165.  
  166.     procedure MAIN (paramPtr: XCmdPtr);
  167.  
  168. implementation
  169.  
  170.     procedure reportToUser (paramPtr: XCmdPtr;
  171.                                     msgStr: str255);
  172. {}
  173. { report something back to the user.  }
  174. { the last parameter (optional) to an external may contain }
  175.  { "noDialog" or "noDialog:GlobalName".  GlobalName is the name }
  176.  { of a HyperTalk global variable into which error messages will be }
  177.  { placed.  we've decided to use this approach to avoid confusing }
  178. { an error message with a valid result being returned from an XFCN. }
  179. {}
  180.         var
  181.             tempStr: str255;
  182.     begin
  183. {check the last param to see if the user requested that}
  184. { we suppress the error dialog }
  185.         ZeroToPas(paramPtr, paramPtr^.params[paramPtr^.paramCount]^, tempStr);
  186.         UprString(tempStr, true);
  187.         if pos('NODIALOG', tempStr) = 0 then
  188.     { no special error handling specified, throw up a dialog and return the error message }
  189.             begin
  190.                 SendCardMessage(paramPtr, concat('answer "', msgStr, '"'));
  191.                 paramPtr^.returnValue := PasToZero(paramPtr, msgStr);
  192.             end
  193.         else if (pos(':', tempStr) > 0) then
  194.     { requested global AND noDialog so we fill in the global and return empty }
  195.             begin
  196.                 tempStr := copy(tempStr, pos(':', tempStr) + 1, length(tempStr));
  197.                                                         { get the name of the HC global  to fill }
  198.                 SetGlobal(paramPtr, tempStr, PasToZero(paramPtr, msgStr));
  199.                                                         { and fill it }
  200.                 paramPtr^.returnValue := PasToZero(paramPtr, '');      { return empty }
  201.             end
  202.         else
  203.     { requested noDialog only so we return the error condition as the result }
  204.             paramPtr^.returnValue := PasToZero(paramPtr, msgStr);
  205.     end;     { procedure }
  206.  
  207.     function AskedForHelp (paramPtr: XCmdPtr;
  208.                                     syntaxMsg: Str255;
  209.                                     copyrightMsg: Str255): boolean;
  210. {   check to see if the user sent a '?' or a '!' as }
  211. { the only parameter. if so we will respond with }
  212. { the calling syntax or the copyright/version info }
  213. { for this external }
  214. {}
  215.         var
  216.             firstStr: str255;
  217.     begin
  218.         askedForHelp := false;
  219.         if paramPtr^.paramCount = 1 then
  220.             begin
  221.                 ZeroToPas(paramPtr, paramPtr^.params[1]^, firstStr);
  222.                     { what is the first param? }
  223.                 if firstStr = '?' then
  224.                     begin
  225.                         reportToUser(paramPtr, syntaxMsg);
  226.                         askedForHelp := true
  227.                     end  { asked for help }
  228.                 else if firstStr = '!' then
  229.                     begin
  230.                         reportToUser(paramPtr, copyRightMsg);
  231.                         askedForHelp := true
  232.                     end;     { asked for copyright info }
  233.             end;     { one parameter passed }
  234.     end;     { function }
  235.  
  236.     function LongToString (paramPtr: XCmdPtr;
  237.                                     num: LONGINT): Str255;
  238. { why, oh why did dan write this one as a procedure??? }
  239.         var
  240.             tempStr: str255;
  241.     begin
  242.         LongToStr(paramPtr, num, tempStr);
  243.         LongToString := tempStr;
  244.     end;
  245.  
  246.     function BitTest (AddressToCheck: ptr;
  247.                                     TotalBits: integer;
  248.                                     BitToTest: longint): boolean;
  249.     { function that allows caller to use std. 68000 bit notation instead of the Toolbox's reversed notation}
  250.     { example:  bit 0 (the least significant bit) in a byte is bit 7 in the Toolbox's notation}
  251.     begin
  252.         BitTest := BitTst(AddressToCheck, TotalBits - 1 - BitToTest);
  253.     end;
  254.  
  255.     function AUXisRunning: boolean;
  256.         const
  257.             HWCfgFlag = $0B22;
  258.     begin
  259.         AUXisRunning := BitTest(pointer(HWCfgFlag), 16, 9);
  260.     end;
  261.  
  262.     procedure SCSINameToID (paramPtr: XCmdPtr);
  263.         { the BITNOT of a driver's ref num is it's number in the unit table.  in the case of a driver for a SCSI disk the entry }
  264.         {   in the unit table is the drive's ID + 32 }
  265.         var
  266.             requestedVolName, volName: str255;
  267.             PB: HParamBlockRec;
  268.             volInfoErr: OSErr;
  269.             lastChar: char;
  270.             diskID: integer;
  271.     begin
  272.         if askedForHelp(paramPtr, 'SCSINameToID(diskName,<ΓÇ£noDialogΓÇ¥:errorGlobal>)', '┬⌐ 1989 Apple Computer, Inc., v.1.1, by Eric Carlson, ') then
  273.             exit(SCSINameToID);
  274.  
  275.         if paramPtr^.paramCount < 1 then                    { we need the disk name to search for }
  276.             begin
  277.                 reportToUser(paramPtr, 'Disk name expected');
  278.                 exit(SCSINameToID)
  279.             end;
  280.  
  281.         ZeroToPas(paramPtr, paramPtr^.params[1]^, requestedVolName);
  282.         if not (AUXisRunning) then                             { it we're NOT running under A/UX (where names ARE case sensitive), }
  283.             begin
  284.                 UprString(requestedVolName, true);             { set the name to uppercase for comparison }
  285.                 if pos(':', requestedVolName) <> 0 then         { make sure the volume name doesn't have a colon }
  286.                     requestedVolName := copy(requestedVolName, 1, pos(':', requestedVolName) - 1);
  287.             end
  288.         else if length(requestedVolName) > 1 then       { we ARE under A/UX, and the disk name isn't one char long }
  289.             begin
  290.                 lastChar := requestedVolName[length(requestedVolName)];   { grab the last char of the path }
  291.                 if (lastChar = ':') or (lastchar = '/') then     { name specified with directory sep char, drop it }
  292.                     requestedVolName := copy(requestedVolName, 1, length(requestedVolName) - 1);
  293.             end;
  294.  
  295.         zeroBytes(paramPtr, @PB, sizeOf(PB));             { start out with a clean paramblock }
  296.         PB.ioNamePtr := @volName;
  297.         PB.ioVolIndex := 0;
  298.         repeat
  299.             PB.ioVolIndex := PB.ioVolIndex + 1;               { next volume }
  300.             volInfoErr := PBHGetVInfo(@PB, false);             { get the next volume name }
  301.             if volInfoErr = noErr then
  302.                 UprString(volName, true);                      { set the name to uppercase for comparison }
  303.         until (volInfoErr <> noErr) or (volName = requestedVolName);
  304.  
  305.         if volInfoErr = noErr then           { return the ID }
  306.             begin
  307.                 diskID := BITNOT(PB.ioVDRefNum) - 32;
  308.                 if (diskID >= 0) and (diskID < 7) then
  309.                     paramPtr^.returnValue := PasToZero(paramPtr, LongToString(paramPtr, diskID))
  310.                 else
  311.                     paramPtr^.returnValue := PasToZero(paramPtr, concat(requestedVolName, ' is not a SCSI drive.'));
  312.             end
  313.         else
  314.             reportToUser(paramPtr, 'Volume not found.')       { return the message }
  315.  
  316.     end;         { procedure volumeList}
  317.  
  318.     procedure MAIN (paramPtr: XCmdPtr);
  319.     begin
  320.         SCSINameToID(paramPtr);
  321.     end;
  322.  
  323. end.     { unit SCSINum}